<template>
  <div id="app">
    <router-view :key="key" v-wechat-title="title"></router-view>
  </div>
</template>

<script>
import { getAcitvityInfo, share } from '@/api/app'
import { getQueryVariable } from '@/utils/app'
import { isWeiXin, getIndexUrl } from '@/utils/app'
import QRCode  from "qrcodejs2"

export default {
  name: 'app',
  data() {
    return {
      resizeTimer: null,
      title: this.$route.meta.title,
      info: {}
    }
  },
  created() {
    //获取活动详情
    this.$toast.loading({
      message: '加载中...',
      forbidClick: false,
      loadingType: 'spinner',
      duration: 10000
    });
    getAcitvityInfo({q: process.env.VUE_APP_Q}).then(res=>{
      this.title = res.share_title
      this.$store.commit('SET_ACC', res)
      this.info = res
      this.$toast.clear();
      if(isWeiXin())this.getShare()
    })
  // var vConsole = new VConsole();
    this.initFontSize()
    window.onresize = () => {
      clearTimeout(this.resizeTimer)
      this.resizeTimer = setTimeout(() => {
        this.initFontSize()
      }, 500)
    }
  },
  methods: {
    initFontSize() {
      let width = document.documentElement.clientWidth || document.body.clientWidth
      // 设计稿750px 2倍屏 html的font-size:50px
      let R_font = (width * 2) / 750 * 50
      document.querySelector('html').style.fontSize = `${R_font}px`
    },
    getShare() {
      share({url: location.href.split('#')[0]}).then(res=> {
        var jweixin = require('jweixin-module')
        jweixin.config(JSON.parse(res))
        let _this = this
        jweixin.ready(function(){
          let title = _this.info.title
          let desc = _this.info.share_desc
          let img = _this.info.share_thumb
          let link = getIndexUrl(_this.info.code)
          console.log(link)
          jweixin.updateAppMessageShareData({ 
            title: title, // 分享标题
            desc: desc, // 分享描述
            link: link, // 分享链接，该链接域名或路径必须与当前页面对应的公众号JS安全域名一致
            imgUrl: img, // 分享图标
            success: function () {
              // 设置成功
            }
          })
          jweixin.updateTimelineShareData({ 
            title: title, // 分享标题
            link: link, // 分享链接，该链接域名或路径必须与当前页面对应的公众号JS安全域名一致
            imgUrl: img, // 分享图标
            success: function () {
              // 设置成功
            }
          })
          
        })
      })
    }
  },
  computed:{
		key(){
			return this.$route.path + Math.random();
		}
	}

}
</script>
<style>
  #__vconsole{ font-size: 12px!important }
</style>

